# v_short_carplan--引航员
# V_SHORT_PORTCARPLAN--港车时间id=1

{createAction} = require('redux-actions')

actions =
  getPilotListStart:createAction('GCSJ/GET_PILOT_LIST_START')
  getPilotListCompleted:createAction('GCSJ/GET_PILOT_LIST_COMPLETED')
  refreshPilotListStart:createAction('GCSJ/REFRESH_PILOT_LIST_START')
  refreshPilotListCompleted:createAction('GCSJ/REFRESH_PILOT_LIST_COMPLETED')

  getCarListStart:createAction('GCSJ/GET_CAR_LIST_START')
  getCarListCompleted:createAction('GCSJ/GET_CAR_LIST_COMPLETED')
  refreshCarListStart:createAction('GCSJ/REFRESH_CAR_LIST_START')
  refreshCarListCompleted:createAction('GCSJ/REFRESH_CAR_LIST_COMPLETED')
  fetchPilotGetList:(pageNum)->
    (dispatch)->
      debugger
      dispatch actions.getPilotListStart()
      fetch("http://202.136.214.173/api/PortCarTime?pageNum=#{pageNum}",{
          method: 'GET'
          mode: 'cors'
          cache: 'default'
          headers: { 'Content-Type':'application/x-www-form-urlencoded'}
          # body:"pageNum=#{pageNum}&state=1"
        })
      .then (res)->
        res.json()
      .then (json)->
        #获取当前时间
        dispatch actions.getPilotListCompleted
          list:json
          lastFetchTime:new Date()
      .catch (err)->
        console.log(err)
  fetchPilotRefreshList:->
    (dispatch)->
      debugger
      dispatch actions.refreshPilotListStart()
      fetch("http://202.136.214.173/api/PortCarTime",{
          method: 'GET'
          mode: 'cors'
          cache: 'default'
          headers: { 'Content-Type':'application/x-www-form-urlencoded'}
          # body:"pageNum=#{pageNum}&state=1"
        })
      .then (res)->
        debugger
        res.json()
      .then (json)->
        debugger
        dispatch actions.refreshPilotListCompleted
          list:json
          lastFetchTime:new Date()
      .catch (err)->
        debugger
        console.log(err)

  fetchCarGetList:(pageNum)->
    (dispatch)->
      debugger
      dispatch actions.getCarListStart()
      fetch("http://202.136.214.173/api/PortCarTime?pageNum=#{pageNum}&id=1",{
          method: 'GET'
          mode: 'cors'
          cache: 'default'
          headers: { 'Content-Type':'application/x-www-form-urlencoded'}
          # body:"pageNum=#{pageNum}&state=1"
        })
      .then (res)->
        res.json()
      .then (json)->
        #获取当前时间
        dispatch actions.getCarListCompleted
          list:json
          lastFetchTime:new Date()
      .catch (err)->
        console.log(err)
  fetchCarRefreshList:->
    (dispatch)->
      dispatch actions.refreshCarListStart()
      fetch("http://202.136.214.173/api/PortCarTime?id=1",{
          method: 'GET'
          mode: 'cors'
          cache: 'default'
          headers: { 'Content-Type':'application/x-www-form-urlencoded'}
          # body:"pageNum=#{pageNum}&state=1"
        })
      .then (res)->
        res.json()
      .then (json)->
        debugger
        dispatch actions.refreshCarListCompleted
          list:json
          lastFetchTime:new Date()
      .catch (err)->
        console.log(err)


module.exports = actions
